﻿@model DLM.Web.ViewModel.CountrySelectionPageView
@using DLM.Domain.DTO;
@using DLM.Services.Implementations;
@{
    var provinces = PageDataService.ShowProvince();

    List<SelectListItem> dateList = new List<SelectListItem>
      {
          new SelectListItem{ Text="一个月",Value="1"},
          new SelectListItem{ Text="两个月",Value="2"},
          new SelectListItem{ Text ="三个月", Value = "3"}
      };
}
<script type="text/javascript">
  
    $(document).ready(function () {
        var searchType;
        var key = 0;
        var type = $("#hdPartySearchType");
        $("select option:nth-child(1)").attr("selected", "selected");
        $("#hdPartySearchType").val("");

        $("#ddlProvince").change(function () {
            if ($("#ddlProvince").val() != "" || $("#ddlProvince").val() != 0) {
                if (type.val() == null || type.val() == "") {
                    $("#hdPartySearchType").val("Province");
                    key = 1;
                } else if (type.val() != "Province") {
                    $("#hdPartySearchType").val("Province");
                    key++;
                }
            } else {
                key--;
            }


        });

        $("#SelectedDate").change(function () {
            if ($("#SelectedDate").val() != "" || $("#SelectedDate").val() != 0) {
                if (type.val() == null || type.val() == "") {
                    $("#hdPartySearchType").val("Date");
                    key = 1;
                } else if (type.val() != "Date") {
                    $("#hdPartySearchType").val("Date");
                    key++;
                }
            } else {
                key--;
            }

        });

        $("#SelectedCategory").change(function () {
            if ($("#SelectedCategory").val() != "" || $("#SelectedCategory").val() != 0) {
                if (type.val() == null || type.val() == "") {
                    $("#hdPartySearchType").val("Category");

                    key = 1;
                } else if (type.val() != "Category") {
                    $("#hdPartySearchType").val("Category");
                    key++;

                }
            } else {

                key--;

            }

        });


        $("#btnPartySearch").click(function () {

            if (key >= 3) {
                $("#hdPartySearchType").val("All");
            } else if (key == 2) {
                $("#hdPartySearchType").val("Or");
            } else if (key < 1) {
                return false;
            }
        });
    });

    $(document).ready(function () {


        $("#ddlProvince").change(function () {
            var province = $("#ddlProvince").find("option:selected").val();
            $.getJSON("/Common/FindCity", { province: province }, function (data) {
                var ddlCity = $("#ddlCity");
                ddlCity.empty();
                ddlCity.append($('<option/>', { value:'', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlCity.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });

        $("#ddlCity").change(function () {
            var city = $("#ddlCity").find("option:selected").val();
            $.getJSON("/Common/FindZone", { city: city }, function (data) {
                var ddlZone = $("#ddlZone");
                ddlZone.empty();
                ddlZone.append($('<option/>', { value: '', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlZone.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });

    });

</script>
@Html.DropDownListFor(x => x.SelectedProvince, new SelectList(provinces, "Value", "Text"), "请选择", new { @class = "sel", id = "ddlProvince" })<label class="lb">省</label>
@Html.DropDownListFor(x => x.SelectedCity, new SelectList(Enumerable.Empty<SelectListItem>(), "Value", "Text"), "请选择", new { @class = "sel", id = "ddlCity" })<label class="lb">市</label>
@Html.DropDownListFor(x => x.SelectedZone, new SelectList(Enumerable.Empty<SelectListItem>(), "Value", "Text"), "请选择", new { @class = "sel", id = "ddlZone" })<label class="lb">区</label>
@Html.DropDownListFor(x => x.SelectedDate, new SelectList(dateList, "Value", "Text"), "请选择", new { @class = "sel" })<label class="lb">时间</label>
@Html.DropDownListFor(x => x.SelectedCategory, new SelectList(Model.Categories, "Value", "Text"), "请选择", new { @class = "sel" })<label class="lb">类型</label>
@Html.Hidden("hdPartySearchType", null, new { id = "hdPartySearchType" })
<input type="submit" value="" id="btnPartySearch" class="btn" />

